package fpga

import (
	"fmt"
	"fpga-vboard/pins"
)

type SrcType int

const (
	SrcTypeVerilator SrcType = iota
)

var SynthesisDrivers = map[SrcType]Synthesis{}

func init() {
	SynthesisDrivers[SrcTypeVerilator] = &VerilatorSynth{}
}

type SynthesisConfig struct {
	SrcType   SrcType
	ExtraArgs interface{}
}

type SynthesisResult struct {
	LibPath    string
	InputPins  []*pins.PinDef
	OutputPins []*pins.PinDef
}

type Synthesis interface {
	Synthesize(cfg *SynthesisConfig) (*SynthesisResult, error)
}

func DoSynthesis(cfg *SynthesisConfig) (*SynthesisResult, error) {
	if cfg == nil {
		return nil, fmt.Errorf("no synthesis config provided")
	}
	if SynthesisDrivers[cfg.SrcType] == nil {
		return nil, fmt.Errorf("no synthesis driver for source type %d", cfg.SrcType)
	}
	return SynthesisDrivers[cfg.SrcType].Synthesize(cfg)
}
